<?php
/**
 * wechat_users 表 去掉  province / city  去掉省 / 市
 */

namespace App\Services\DBHelpers;


use App\Models\OpenWechat\WechatUser;
use App\Services\Utils\Transaction;

class WechatUserProvinceCity
{

    /**
     * @deprecated- 线上已更新 2018年8月23日10:09:16
     *
     * \App\Services\DBHelpers\WecahtUserProvinceCity::run()
     *
     * @throws \Exception
     */
    public static function run()
    {
        $wechat_users = (new WechatUser)
            ->where('province', 'like', '%省%')
            ->orWhere('province', 'like', '%市%')
            ->orWhere('city', 'like', '%市%')
            ->get();

        $update = Transaction::handle(function () use ($wechat_users) {
            $update = [];
            foreach ($wechat_users as $wechat_user) {
                $update[] = $wechat_user->update([
                    'province' => $wechat_user->province,
                    'city'     => $wechat_user->city,
                ]);
            }
            return $update;
        });

        return 'update ' . count($update);
    }
}